package adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.boltshow.R;
import com.squareup.picasso.Picasso;

import java.util.List;

import model.BrandDetailModel;

/**
 * Created by lenovo on 2016/8/29.
 */
public class BrandsDetailAdapter extends RecyclerView.Adapter<BrandsDetailAdapter.MyViewHolder> {
    private Context mContext;
    private List<BrandDetailModel.DataBean> mData;
    private View.OnClickListener mOnClickListener;


    public BrandsDetailAdapter(Context mContext, List<BrandDetailModel.DataBean> mData) {
        this.mContext = mContext;
        this.mData = mData;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_brandsdetail_show,null);

        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
                holder.tvBuyupnum.setText(mData.get(position).getBuyupnum());
                holder.tvContent.setText(mData.get(position).getGoodsName());
                holder.tvShopPrice.setText(mData.get(position).getShopPrice());
                Picasso.with(mContext).load(mData.get(position).getImg640url()).into(holder.ivBg);
                holder.ivBg.setTag(position);
                holder.ivBg.setOnClickListener(mOnClickListener);

    }

    @Override
    public int getItemCount() {
        return mData==null?0:mData.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder{
        private TextView tvShopPrice,tvBuyupnum,tvContent;
        private ImageView ivBg;

        public MyViewHolder(View itemView) {
            super(itemView);
            ivBg= (ImageView) itemView.findViewById(R.id.iv_brandDetail_bg);
            tvShopPrice= (TextView) itemView.findViewById(R.id.tv_brandDetail_shopPrice);
            tvBuyupnum= (TextView) itemView.findViewById(R.id.tv_brandDetail_tvBuyupnum);
            tvContent= (TextView) itemView.findViewById(R.id.tv_brandDetail_content);


        }
    }
    public  void setOnClickListener(View.OnClickListener mOnClickListener){
        this.mOnClickListener=mOnClickListener;
    }

}
